<?php
// $Id: results.tpl.php,v 1.5 2007/10/11 09:51:29 goba Exp $
global $base_url,$language;
  $url = $base_url . '/' . drupal_get_path('module', 'forms');
//print_r($language);
//print "<pre>";print_r($items); print"</pre>";
  if($language->language=='ta'){
	$lang= '/ta';
  }else{
	 $lang=''; 
 }

?>
<div class="result_inner">
		<div>
		<?php
			my_db_change(1);
			$depname = db_query('SELECT dept_name FROM {depart_mst} WHERE dep_id = :dep_id', array(':dep_id' => $depid))->fetchField();
			my_db_change(0);
		?>
		<?php if($depname != ''){?>
		<div class="res_dept"><span >
			<strong><?php echo t($depname)?></strong></span>
		<?php } ?>
			<span class="backbut">
			<a href="<?php print $base_url.$lang;?>/forms/deptname"><?php print t('Back')?></a></span>
		</div>
		
		<?php 
		$i=0;           
		 foreach($items as $nid){
		 	my_db_change(1);
		 	$vid = db_query('SELECT vid FROM {node} WHERE nid = :nid', array(':nid' => $nid))->fetchField();
		 	$row = node_load($nid, $vid);
		 	my_db_change(0);
		 	
		 if ($row->field_form_upload['und'][0]['filesize'] != '0') {
			$kb = ceil($row->field_form_upload['und'][0]['filesize']/1024);
			$kbyte= $kb.KB;
			if($kb >1024) { 
			  $kb = ceil($kb/1024);
			  $kbyte= $kb.MB;
			}
		}
		 if ($row->field_form_type['und'][0]['value'] == 'online') {
			$link =  $row->field_form_avail['und'][0]['value'];
			$link ="'$link'";
			$icon ='';
		}
		else if($row->field_form_type['und'][0]['value'] == 'download') {
		     $link= $row->field_form_upload['und'][0]['uri'];		
		     $wrapper = file_stream_wrapper_get_instance_by_uri($link);
			if($wrapper == true){
				 $pathfile = $wrapper->getDirectoryPath() . "/" . file_uri_target($link);
			}
			/*$split=explode('dorms/',$pdf_url);
			$onclick_url=$split[1];*/
			$link="'http://cms.tn.gov.in/tncms_latest/$pathfile '";
			$icon = '<img alt="Download Icon" src="http://cms.tn.gov.in/sites/default/files/icons/pdf_icon.gif">
						<span class="kb">
							<span>('.$kbyte.')</span>
						</span>		';
		}
		
		?>
			<div class="res_title_ch" style="">
				 <p><a onclick="return tnportal_window(<?php print $link ?>);" href="javascript:void(0);" >
						<?php echo  ucfirst(t($row->title)).$icon  ?>  
					</a>
				 </p>
			</div>			
		<?php $i++; } ?>
		<?php if($i == '0'){?>
			 <div class="no_record">No Results Found </div>
		<?php }	?>
	</div>
<div class="clr"></div>
</div>

